'use strict'

const fs = require('fs')
const path = require('path')

let pageName = process.argv.slice(2)


function readFile(fileName) {
    return fs.readFileSync(
        path.join(__dirname, fileName),
        'utf8'
    )
}

function initPageFolder(pageName, tpls) {
    fs.mkdirSync(path.join(__dirname, `../src/${pageName}`));
    
    fs.writeFileSync(
        path.join(__dirname, `../src/${pageName}/${pageName}.js`),
        tpls["js"]
    )
    fs.writeFileSync(
        path.join(__dirname, `../src/${pageName}/api.js`),
        tpls["api"]
    )
    fs.writeFileSync(
        path.join(__dirname, `../src/${pageName}/App.vue`),
        tpls["vue"]
    )
}

let jsTpl = readFile('index.js')
let vueTpl = readFile('App.vue')
let apiJs = readFile('api.js')

initPageFolder(pageName, { js: jsTpl, vue: vueTpl, api: apiJs});

